package com.yonyou.cyxdms.sysAuth.service.controller.userorgsource;

import org.springframework.web.bind.annotation.*;
import com.yonyou.cyx.framework.controller.base.BaseController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import com.yonyou.cyxdms.sysAuth.service.service.userorgsource.UserorgSourceService;
import com.yonyou.cyxdms.sysAuth.service.dto.userorgsource.UserorgSourceDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

import org.springframework.http.MediaType;

import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;

import io.swagger.annotations.*;


/**
 *
 * @author zhangtan
 * @since 2020-07-07
 */
@Api(value = "厂端人员组织与线索来源关系表模块名称", tags = {"厂端人员组织与线索来源关系表模块名称"})
@RestController
@RequestMapping("/userorgsource/userorgSource")
public class UserorgSourceController extends BaseController {

	private final Logger logger = LoggerFactory.getLogger(UserorgSourceController.class);

	@Autowired
	private UserorgSourceService userorgSourceService;

	/**
	 * 分页查询数据
	 *
	 * @param queryCondition 查询条件
	 * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
	 * @author zhangtan
	 * @since 2020-07-07
	 */
	@ResponseBody
	@GetMapping
	@SuppressWarnings("unchecked")
	@ApiOperation(value = "厂端人员组织与线索来源关系表模块名称分页查询", notes = "厂端人员组织与线索来源关系表模块名称分页查询", httpMethod = "GET",
			produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
	public IPage<Map<String,Object>> getList (@RequestParam Map<String,Object> queryCondition, @RequestParam
		("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
		LoginInfoDto loginInfo = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
		if(queryCondition!=null){
			queryCondition.put("appId",loginInfo.getAppId());
		}
		Page<Map<String,Object>> page = new Page(currentPage, pageSize);
		return userorgSourceService.selectPageBysql(page, queryCondition);
	}

	/**
	 * 按ID查询数据
	 *
	 * @param id 数据主键ID
	 * @return  Map<String,Object> 数据对应的map 结构
	 * @author zhangtan
	 * @since 2020-07-07
	 */
	@ResponseBody
	@GetMapping(value="/{id}")
	@ApiOperation(value = "厂端人员组织与线索来源关系表模块名称明细查询", notes = "厂端人员组织与线索来源关系表模块名称明细查询", httpMethod = "GET",
			produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
	public Map<String,Object> getById(@PathVariable("id") Long id) {
		return userorgSourceService.getById(id);
	}

	/**
	 * 进行数据新增
	 *
	 * @param userorgSourceDTO 需要保存的DTO
	 * @return Map<String,Object> 返回的数据map
	 * @author zhangtan
	 * @since 2020-07-07
	 */
	@ResponseBody
	@PostMapping
	@ResponseStatus(HttpStatus.CREATED)
	@ApiOperation(value = "厂端人员组织与线索来源关系表模块名称新增", notes = "厂端人员组织与线索来源关系表模块名称新增", httpMethod = "POST",
			produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
	public Map<String,Object> insert(@RequestBody UserorgSourceDTO userorgSourceDTO) {
		logger.debug("userorgSourceDTO:{}",userorgSourceDTO);
		return userorgSourceService.insert( userorgSourceDTO);
	}

	/**
	 * 进行数据修改
	 *
	 * @param id 需要修改数据的ID
	 * @param userorgSourceDTO 需要保存的DTO
	 * @return Map<String,Object> 返回的数据map
	 * @author zhangtan
	 * @since 2020-07-07
	 */
	@ResponseBody
	@PutMapping(value="/{id}")
	@ResponseStatus(HttpStatus.CREATED)
	@ApiOperation(value = "厂端人员组织与线索来源关系表模块名称修改", notes = "厂端人员组织与线索来源关系表模块名称修改", httpMethod = "PUT",
			produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
	public Map<String,Object> update(@PathVariable("id") Long id, @RequestBody UserorgSourceDTO userorgSourceDTO) {
		logger.debug("userorgSourceDTO:{}",userorgSourceDTO);
		return userorgSourceService.update(id,userorgSourceDTO);
	}

	/**
	 * 根据id删除对象
	 *
	 * @param id 需要修改数据的ID
	 * @author zhangtan
	 * @since 2020-07-07
	 */
	@DeleteMapping(value="/{id}")
	@ResponseStatus(HttpStatus.NO_CONTENT)
	@ApiOperation(value = "厂端人员组织与线索来源关系表模块名称删除", notes = "厂端人员组织与线索来源关系表模块名称删除", httpMethod = "DELETE",
			produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
	public boolean deleteById(@PathVariable("id") Long id){
		logger.debug("删除ID:{}",id);
		userorgSourceService.deleteById(id);
		return true;
	}

	/**
	 * 根据IDs批量删除对象
	 *
	 * @param ids 需要修改数据的ID集合
	 * @author zhangtan
	 * @since 2020-07-07
	 */
	@DeleteMapping(value="/batch/{ids}")
	@ResponseStatus(HttpStatus.NO_CONTENT)
	@ApiOperation(value = "厂端人员组织与线索来源关系表模块名称批量删除", notes = "厂端人员组织与线索来源关系表模块名称批量删除", httpMethod = "DELETE",
			produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@ApiImplicitParams({@ApiImplicitParam(value = "用户id", name = "userId", required = true, dataType = "string", paramType = "header")})
	public boolean deleteByIds(@PathVariable("ids") String ids){
		logger.debug("删除ID:{}",ids);
		userorgSourceService.deleteBatchIds(ids);
		return true;
	}


}